package server.session.handler;

import server.session.UserSession;
import unit.request.GetContactListRequest;
import unit.request.Request;
import unit.response.GetContactListRequestResponse;

import java.io.IOException;

/**
 * @author Yuri Denison
 * @since 08.08.11
 */
public class GetContactListRequestHandler implements RequestHandler {
    @Override
    public void handleRequest(Request request, UserSession userSession) {
        GetContactListRequest getContactListRequest = (GetContactListRequest) request;
        String[] projective = getContactListRequest.getProjective();
        if (projective == null) {
            projective = userSession.getDataStorage().getUserInfoProjective();
        }
        GetContactListRequestResponse response = new GetContactListRequestResponse(
                getContactListRequest.getRequestID(),
                userSession.getSession(),
                projective,
                userSession.getDataStorage().getContactList(userSession.getUserId()),
                userSession.getDataStorage().getContactListInfo(userSession.getUserId(), getContactListRequest.getProjective())
        );
        try {
            userSession.getConnector().send(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
